//
//  GUILayer.cpp
//  ColourAssault
//
//  Created by Cloner Team on 8/22/14.
//
//

#include "GUILayer.h"

GUILayer::GUILayer() {
    this->buttonArrays = __Array::create();
    CC_SAFE_RETAIN(this->buttonArrays);
    for(int i = 0; i < 4; i++) {
        choice[i] = false;
    }
    
    this->createLayers();
    this->createLayersContent();
    this->initialize();
}

GUILayer::~GUILayer() {
    Utils::safeRelease(this->buttonArrays);
}

void GUILayer::onEnter() {
    Layer::onEnter();
    this->touchesRegister();
}

void GUILayer::onExit() {
    Layer::onExit();
    this->removeAllChildrenWithCleanup(true);
}

void GUILayer::touchesRegister() {
    auto listener = EventListenerTouchAllAtOnce::create();
    listener->onTouchesBegan = CC_CALLBACK_2(GUILayer::onTouchesBegan, this);
    listener->onTouchesEnded = CC_CALLBACK_2(GUILayer::onTouchesEnded, this);
    listener->onTouchesMoved = CC_CALLBACK_2(GUILayer::onTouchesMoved, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}

void GUILayer::onTouchesBegan(const std::vector<Touch*>& touches, Event* event) {
    GameModel* gameModel = GameModel::getInstance();
    FiniteTimeAction* fadeInAction = FadeTo::create(0.7f, 100);
    for (auto touch : touches) {
        Point point = this->convertTouchToNodeSpace(touch);
        //check circle
        {
            ArcBody* arcBody = new ArcBody(this->circle->getContentSize().width/2, 360);
            arcBody->setPosition(Point(this->circle->getPositionX(), this->circle->getPositionY()));
            if (arcBody->contains(point)) {
                this->notify(REQ_PLAY_GAME, EVT_CLICK_BUTTON, NULL, 0, NULL);
            }
        }
        //check buttons
        if (gameModel->getGameState() == GS_PLAY)
        {
            for(int i = 0; i < this->buttonArrays->count();i++) {
                Face* button = (Face*) this->buttonArrays->getObjectAtIndex(i);
                RectBody* rectBody = new RectBody(button->getContentSize().width, button->getContentSize().height);
                rectBody->setPosition(button->getPosition());
                if(rectBody->contains(point))
                {
                    choice[i] = true;
                    UGLayerColor* grayLayer = (UGLayerColor*)button->getChildByTag(0);
                    grayLayer->runAction(fadeInAction);
                }
            }
        }
    }
}

void GUILayer::onTouchesMoved(const std::vector<Touch*>& touches, Event* event) {
    GameModel* gameModel = GameModel::getInstance();
    if (gameModel->getGameState() == GS_PLAY) {
        for (auto touch : touches) {
            Point point = this->convertTouchToNodeSpace(touch);
            //check buttonRed
            {
                for(int i = 0; i < this->buttonArrays->count(); i++) {
                    Face* button = (Face*) this->buttonArrays->getObjectAtIndex(i);
                    RectBody* rectBody = new RectBody(button->getContentSize().width, button->getContentSize().height);
                    rectBody->setPosition(button->getPosition());
                    if(!rectBody->contains(point))
                    {
                        choice[i] = false;
                        UGLayerColor* grayLayer = (UGLayerColor*)button->getChildByTag(0);
                        grayLayer->setOpacity(0);
                        grayLayer->stopAllActions();
                    }
                }
            }
        }
    } else {
        for (int i = 0; i < 4; i++) {
            choice[i] = false;
        }
    }
}
void GUILayer::onTouchesEnded(const std::vector<Touch*>& touches, Event* event) {
    GameModel* gameModel = GameModel::getInstance();
    if (gameModel->getGameState() == GS_PLAY) {
        for(auto touch : touches) {
            Point point = this->convertTouchToNodeSpace(touch);
            //check buttons
            for(int i = 0; i < this->buttonArrays->count(); i++) {
                Face* button = (Face*) this->buttonArrays->getObjectAtIndex(i);
                UGLayerColor* grayLayer = (UGLayerColor*)button->getChildByTag(0);
                grayLayer->setOpacity(0);
                grayLayer->stopAllActions();
                
                RectBody* rectBody = new RectBody(button->getContentSize().width, button->getContentSize().height);
                rectBody->setPosition(button->getPosition());
                if(rectBody->contains(point) && choice[i] == true && gameModel->canChoose == true)
                {
                    Color* color = gameModel->getColorQueue().front();
                    switch(i) {
                        case 0: //RED
                        {
                            if(color -> getCorrectColor() == RED) {
                                this->notify(REQ_CORRECT_CHOICE, EVT_DEFAULT, NULL, 0, NULL);
                            } else {
                                this->notify(REQ_INCREASE_SPEED, EVT_DEFAULT, NULL, 0, NULL);
                            }
                            break;
                        }
                        case 1:
                        {
                            if(color->getCorrectColor() == BLUE) {
                                this->notify(REQ_CORRECT_CHOICE, EVT_DEFAULT, NULL, 0, NULL);
                            } else {
                                this->notify(REQ_INCREASE_SPEED, EVT_DEFAULT, NULL, 0, NULL);
                            }
                            break;
                        }
                        case 2:
                        {
                            if(color->getCorrectColor() == YELLOW) {
                                this->notify(REQ_CORRECT_CHOICE, EVT_DEFAULT, NULL, 0, NULL);
                            } else {
                                this->notify(REQ_INCREASE_SPEED, EVT_DEFAULT, NULL, 0, NULL);
                            }
                            break;
                        }
                        case 3:
                        {
                            if(color->getCorrectColor() == GREEN) {
                                this->notify(REQ_CORRECT_CHOICE, EVT_DEFAULT, NULL, 0, NULL);
                            } else {
                                this->notify(REQ_INCREASE_SPEED, EVT_DEFAULT, NULL, 0, NULL);
                            }
                            break;
                        }
                    }
                }
                
            }
        }
        for (int i=0; i<4; i++) {
            choice[i] = false;
        }
    }
}

void GUILayer::initialize(){
    GameModel* gameModel = GameModel::getInstance();
    this->guiListener = GUIListener::create();
    this->guiListener->setHandlerObj(this);
    this->guiListener->setDisplayMenu(ug_listener_func(GUILayer::onDisplayMenu));
    this->guiListener->setDisplayGame(ug_listener_func(GUILayer::onDisplayGame));
    this->guiListener->setDisplayResult(ug_listener_func(GUILayer::onDisplayResult));
    gameModel->addListener(this->guiListener);
}

void GUILayer::update(float dt) {
    GameModel* gameModel = GameModel::getInstance();
    //GS_PLAY
    if(gameModel->getGameState() == GS_PLAY) {
        char scoreText[100];
        sprintf(scoreText, "%d", gameModel->getCurrentScore());
        Label* scoreLabel = (Label*)this->gameLayer->getChildByTag(0);
        scoreLabel->setString(scoreText);
    }
}

void GUILayer::createLayers(){
    this->menuLayer = UGLayer::create();
    this->menuLayer->setPosition(Point::ZERO);
    this->addChild(this->menuLayer);
    
    this->gameLayer = UGLayer::create();
    this->gameLayer->setPosition(Point::ZERO);
    this->addChild(this->gameLayer);
}

void GUILayer::createLayersContent(){
    GameModel* gameModel = GameModel::getInstance();
    Size gameSize = gameModel->getDisplayResolutionSize();
    /*------MENU LAYER-------*/
    //logo
    this->logo = new Face();
    this->logo->initWithSpriteFrameName((char*)ANI_LOGO);
    this->logo->setPosition(gameSize.width/2, (gameSize.height+480)*48/100 + 200);
    this->menuLayer->addChild(this->logo,10);
    
    //cirlce
    this->circle = new Face();
    this->circle->initWithSpriteFrameName((char*)ANI_CIRCLE);
    this->circle->setPosition(gameSize.width/2, (gameSize.height + 480)*48/100);
    this->menuLayer->addChild(this->circle);
    
    UGMenu* upperMenu = UGMenu::create();
    upperMenu->setPosition(Point::ZERO);
    this->circle->addChild(upperMenu);
    //buttonFacebook
    this->buttonFacebook = Utils::createButton((char*)ANI_BUTTON_FACEBOOK);
    this->buttonFacebook->setPosition(this->circle->getContentSize().width,this->circle->getContentSize().height/2 + this->buttonFacebook->getContentSize().height/2 + 10);
    upperMenu->addChild(this->buttonFacebook);
    this->buttonFacebook->setCallback(CC_CALLBACK_1(GUILayer::onButtonClick, this));
    //buttonTwitter
    this->buttonShare = Utils::createButton((char*)ANI_BUTTON_SHARE);
    this->buttonShare->setPosition(this->circle->getContentSize().width,this->circle->getContentSize().height/2 - this->buttonShare->getContentSize().height/2 - 10);
    upperMenu->addChild(this->buttonShare);
    this->buttonShare->setCallback(CC_CALLBACK_1(GUILayer::onButtonClick, this));
    //buttonRank
    this->buttonRank = Utils::createButton((char*)ANI_BUTTON_BXH);
    this->buttonRank->setPosition(0,this->circle->getContentSize().height/2 + this->buttonRank->getContentSize().height/2 + 10);
    upperMenu->addChild(this->buttonRank);
    this->buttonRank->setCallback(CC_CALLBACK_1(GUILayer::onButtonClick, this));
    //buttonMedal
    this->buttonMedal = Utils::createButton((char*)ANI_BUTTON_MEDAL);
    this->buttonMedal->setPosition(0,this->circle->getContentSize().height/2 - this->buttonMedal->getContentSize().height/2 - 10);
    upperMenu->addChild(this->buttonMedal);
    //label Tap to play
    Label* tabLabel = Utils::createLabel((char*)TXT_TAP_TO_PLAY,(char*)FONT_DEKAR, 45);
    tabLabel->setColor(Color3B(128,128,128));
    tabLabel->setPosition(this->circle->getContentSize().width/2, this->circle->getContentSize().height/2);
    tabLabel->setTag(0);
    this->circle->addChild(tabLabel);
    //score Text  label
    Label* scoreTextLabel = Utils::createLabel((char*)TXT_SCORE, (char*)FONT_DEKAR, 40);
    scoreTextLabel->setColor(Color3B(128,128,128));
    scoreTextLabel->setPosition(this->circle->getContentSize().width/2, this->circle->getContentSize().height*2/3+20);
    scoreTextLabel->setVisible(false);
    scoreTextLabel->setTag(1);
    this->circle->addChild(scoreTextLabel);
    //result label
    Label* resultLabel = Utils::createLabel((char*)"0", (char*)FONT_VPSALT, 130);
    resultLabel->setColor(Color3B(128,128,128));
    resultLabel->setPosition(this->circle->getContentSize().width/2, this->circle->getContentSize().height/2);
    resultLabel->setVisible(false);
    resultLabel->setTag(2);
    this->circle->addChild(resultLabel);
    
    UGMenu* lowerMenu = UGMenu::create();
    lowerMenu->setPosition(Point::ZERO);
    this->menuLayer->addChild(lowerMenu);
    //buttonRemoveAds
    this->buttonRemoveAds = Utils::createButton((char*)ANI_BUTTON_REMOVE_ADS_1, (char*)ANI_BUTTON_REMOVE_ADS_2);
    this->buttonRemoveAds->setPosition(gameSize.width/2 - this->buttonRemoveAds->getContentSize().width/2, this->buttonRemoveAds->getContentSize().height/2);
    this->buttonRemoveAds->setCallback(CC_CALLBACK_1(GUILayer::onButtonClick, this));
    lowerMenu->addChild(this->buttonRemoveAds);
    //buttonStore
    this->buttonStore = Utils::createButton((char*)ANI_BUTTON_STORE_1, (char*)ANI_BUTTON_STORE_2);
    this->buttonStore->setPosition(gameSize.width/2 - this->buttonStore->getContentSize().width/2, this->buttonRemoveAds->getContentSize().height + this->buttonStore->getContentSize().height/2);
    this->buttonStore->setCallback(CC_CALLBACK_1(GUILayer::onButtonClick, this));
    lowerMenu->addChild(this->buttonStore);
    //buttonMusic
    MenuItemSprite* musicOn = Utils::createButton((char*)ANI_BUTTON_MUSIC_1, (char*)ANI_BUTTON_MUSIC_1);
    MenuItemSprite* musicOff = Utils::createButton((char*)ANI_BUTTON_MUSIC_2, (char*)ANI_BUTTON_MUSIC_2);
    this->buttonMusic = MenuItemToggle::create(musicOn);
    this->buttonMusic->addSubItem(musicOff);
    this->buttonMusic->setPosition(gameSize.width/2 + this->buttonMusic->getContentSize().width/2, this->buttonMusic->getContentSize().height/2);
    this->buttonMusic->setCallback(CC_CALLBACK_1(GUILayer::onButtonClick, this));
    lowerMenu->addChild(this->buttonMusic);
    
    //buttonRate
    this->buttonRate = Utils::createButton((char*)ANI_BUTTON_RATE_1, (char*)ANI_BUTTON_RATE_2);
    this->buttonRate->setPosition( gameSize.width/2 + this->buttonRate->getContentSize().width/2, this->buttonMusic->getContentSize().height + this->buttonRate->getContentSize().height/2);
    this->buttonRate->setCallback(CC_CALLBACK_1(GUILayer::onButtonClick, this));
    lowerMenu->addChild(this->buttonRate);
    
    //Games
    Label* gamesLabel = Utils::createLabel((char*)TXT_GAMES, (char*)FONT_VPSALT, 40);
    gamesLabel->setColor(Color3B(128,128,128));
    gamesLabel->setPosition(this->buttonStore->getPositionX() - this->buttonStore->getContentSize().width/2 + 10 + gamesLabel->getContentSize().width/2, 490);
    this->menuLayer->addChild(gamesLabel);
    
    Label* gamesNumberLabel = Utils::createLabel((char*)"0", (char*)FONT_VPSALT, 45);
    gamesNumberLabel->setColor(Color3B(128,128,128));
    gamesNumberLabel->setPosition(this->buttonStore->getPositionX() - this->buttonStore->getContentSize().width/2 + 55 + gamesNumberLabel->getContentSize().width/2, 525);
    gamesNumberLabel->setTag(0);
    this->menuLayer->addChild(gamesNumberLabel);
    
    //Record
    Label* recordLabel = Utils::createLabel((char*)TXT_RECORD, (char*)FONT_VPSALT, 40);
    recordLabel->setColor(Color3B(128,128,128));
    recordLabel->setPosition(this->buttonRate->getPositionX() + this->buttonRate->getContentSize().width/2 - 10 - recordLabel->getContentSize().width/2, 490);
    this->menuLayer->addChild(recordLabel);
    
    Label* recordNumberLabel = Utils::createLabel((char*)"0", (char*)FONT_VPSALT, 45);
    recordNumberLabel->setColor(Color3B(128,128,128));
    recordNumberLabel->setPosition(this->buttonRate->getPositionX() + this->buttonRate->getContentSize().width/2 - 55 - recordNumberLabel->getContentSize().width/2, 525);
    recordNumberLabel->setTag(1);
    this->menuLayer->addChild(recordNumberLabel);


    
    /*------GAME LAYER-------*/
    UGMenu* gameAnswers = UGMenu::create();
    gameAnswers->setPosition(Point::ZERO);
    this->gameLayer->addChild(gameAnswers);
    for(int i = 0; i < 4 ; i++) {
        Face* button = new Face();
        switch(i)
        {
            case 0:
                button->initWithSpriteFrameName((char*)ANI_BUTTON_RED);
                button->setPosition(gameSize.width/2 - button->getContentSize().width/2, button->getContentSize().height/2);
                break;
            case 1:
                button->initWithSpriteFrameName((char*)ANI_BUTTON_BLUE);
                button->setPosition(gameSize.width/2 - button->getContentSize().width/2, button->getContentSize().height*3/2);
                break;
            case 2:
                button->initWithSpriteFrameName((char*)ANI_BUTTON_YELLOW);
                button->setPosition(gameSize.width/2 + button->getContentSize().width * 1/2, button->getContentSize().height/2);
                break;
            case 3:
                button->initWithSpriteFrameName((char*)ANI_BUTTON_GREEN);
                button->setPosition(gameSize.width/2 + button->getContentSize().width*1/2, button->getContentSize().height*3/2);
                break;
        }

        UGLayerColor* grayLayer = UGLayerColor::create();
        grayLayer->initWithColor(Color4B(0,0,0,0));
        grayLayer->setContentSize(button->getContentSize());
        grayLayer->setPosition(0,0);
        grayLayer->setTag(0);
        button->addChild(grayLayer);
        this->gameLayer->addChild(button);
        this->buttonArrays->addObject(button);
    }
    //score Label
    Label* scoreLabel = Utils::createLabel((char*)"0", (char*)FONT_VPSALT, 50);
    scoreLabel->setPosition(35,gameSize.height - 30);
    scoreLabel->setTag(0);
    scoreLabel->setColor(Color3B(128,128,128));
    this->gameLayer->addChild(scoreLabel);
    
    //highScore Label
    Label* highScoreLabel = Utils::createLabel((char*)"0", (char*)FONT_VPSALT, 50);
    highScoreLabel->setPosition(gameSize.width - 35, gameSize.height - 30);
    highScoreLabel->setTag(1);
    highScoreLabel->setColor(Color3B(128,128,128));
    this->gameLayer->addChild(highScoreLabel);
}

void GUILayer::onDisplayMenu(Ref* data){
    GameModel* gameModel = GameModel::getInstance();
    this->displayBaseOnGameState();
    
    char highScoreText[100];
    sprintf(highScoreText, "%d", gameModel->getHighScore());
    Label* highScoreLabel = (Label*) this->menuLayer->getChildByTag(1);
    highScoreLabel->setString(highScoreText);
    
    char numberGamesText[100];
    sprintf(numberGamesText, "%d", gameModel->getNumberGames());
    Label* numberGamesLabel = (Label*) this->menuLayer->getChildByTag(0);
    numberGamesLabel->setString(numberGamesText);
}

void GUILayer::onDisplayGame(Ref* data){
    GameModel* gameModel = GameModel::getInstance();
    this->displayBaseOnGameState();
    
    char highScoreText[100];
    sprintf(highScoreText, "%d", gameModel->getHighScore());
    Label* highScoreLabel = (Label*) this->gameLayer->getChildByTag(1);
    highScoreLabel->setString(highScoreText);
}

void GUILayer::onDisplayResult(Ref* data){
    GameModel* gameModel = GameModel::getInstance();
    Size gameSize = gameModel->getDisplayResolutionSize();
    this->displayBaseOnGameState();
    //logo
     FiniteTimeAction* moveLogoAction = MoveTo::create(0.4f, this->logo->getPosition());
    this->logo->setPosition(gameSize.width/2, gameSize.height + 200);
    this->logo->runAction(moveLogoAction);
    //facebook button
    FiniteTimeAction* moveFacebookButtonAction = MoveTo::create(0.3f, this->buttonFacebook->getPosition());
    this->buttonFacebook->setPosition(this->circle->getContentSize().width+500,this->circle->getContentSize().height/2 + this->buttonFacebook->getContentSize().height/2 + 10 + 500);
    
    this->buttonFacebook->runAction(moveFacebookButtonAction);
    //buttonShare
    FiniteTimeAction* moveShareButtonAction = MoveTo::create(0.3f, this->buttonShare->getPosition());
    this->buttonShare->setPosition(this->circle->getContentSize().width + 500,this->circle->getContentSize().height/2 - this->buttonShare->getContentSize().height/2 - 10 - 500);
    this->buttonShare->runAction(moveShareButtonAction);
    
    //buttonRank
    FiniteTimeAction* moveRankButtonAction = MoveTo::create(0.3f, this->buttonRank->getPosition());
    this->buttonRank->setPosition(-500,this->circle->getContentSize().height/2 + this->buttonRank->getContentSize().height/2 + 10 + 500);
    this->buttonRank->runAction(moveRankButtonAction);
    
    //buttonMedal
    FiniteTimeAction* moveMedalButtonAction = MoveTo::create(0.3f, this->buttonMedal->getPosition());
    this->buttonMedal->setPosition(-500, this->circle->getContentSize().height/2 - this->buttonMedal->getContentSize().height/2 - 10 - 500);
    this->buttonMedal->runAction(moveMedalButtonAction);
    
    char highScoreText[100];
    sprintf(highScoreText, "%d", gameModel->getHighScore());
    Label* highScoreLabel = (Label*) this->menuLayer->getChildByTag(1);
    highScoreLabel->setString(highScoreText);
    
    char numberGamesText[100];
    sprintf(numberGamesText, "%d", gameModel->getNumberGames());
    Label* numberGamesLabel = (Label*) this->menuLayer->getChildByTag(0);
    numberGamesLabel->setString(numberGamesText);
    
    Label* tabLabel = (Label*) this->circle->getChildByTag(0);
    tabLabel->setPosition(this->circle->getContentSize().width/2, this->circle->getContentSize().height*1/3 - 20);
    
    Label* scoreTextLabel = (Label*) this->circle->getChildByTag(1);
    scoreTextLabel->setVisible(true);
    
    char resultText[100];
    sprintf(resultText, "%d", gameModel->getCurrentScore());
    Label* resultLabel = (Label*) this->circle->getChildByTag(2);
    resultLabel->setVisible(true);
    resultLabel->setString(resultText);
    resultLabel->setPosition(this->circle->getContentSize().width/2, this->circle->getContentSize().height/2 - 10);
}

void GUILayer::onButtonClick(Ref* sender){
    GameModel* gameModel = GameModel::getInstance();
    SoundModel* soundModel = SoundModel::getInstance();
    if(sender == this->buttonMusic) {
        if(this->buttonMusic->getSelectedIndex() == 0){
            soundModel->setBackgroundMusicVolume(1);
            soundModel->setEffectsVolume(1);
        } else {
            soundModel->setEffectsVolume(0);
            soundModel->setBackgroundMusicVolume(0);
        }
    }
    
    if(sender == this->buttonRate) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        AppUtils::openForRate();
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
        Application* application = Application::getInstance();
        application->openURL(":callStore:");
#endif
    }
    
    if(sender == this->buttonRank) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        AppUtils::showLeaderboard();
#endif
    }
    
    if(sender == this->buttonFacebook) {
        char highScoreText[100];
        sprintf(highScoreText,"I've just get the highscore on Colour Assault! My score is %d, what's about you? ", gameModel->getHighScore());
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        AppUtils::shareFacebook("Colour Assault", highScoreText ,"https://farm4.staticflickr.com/3920/15046699366_48d2958ce6_s.jpg", "https://itunes.apple.com/us/app/colour-assault/id911660409?ls=1&mt=8", "Sorry! Cannot connect to your facebook");
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)  
        char highScore[30];
        sprintf(highScore,":callFacebook:%d",gameModel->getHighScore());
        Application* application = Application::getInstance();
        application->getURL(highScore);
#endif

    }
    
    if(sender == this->buttonShare) {
        char highScoreText[100];
        sprintf(highScoreText,"I've just get the highscore on Colour Assault! My score is %d, what's about you? ", gameModel->getHighScore());
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        AppUtils::shareTwitter("Colour Assault", highScoreText, "What a funny game!!!", "https://farm4.staticflickr.com/3920/15046699366_48d2958ce6_s.jpg", "https://itunes.apple.com/us/app/colour-assault/id911660409?ls=1&mt=8", "Sorry! Cannot connect to your twitter");
#endif
        
    }
    
    if(sender == this->buttonRemoveAds) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        AppUtils::buyInApp();
#endif
    }
    
    if(sender == this->buttonShare) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        AppUtils::restoreInApp();
#endif
    }
}

void GUILayer::displayBaseOnGameState(){
    GameModel* gameModel = GameModel::getInstance();
    if(gameModel->getGameState() == GS_MENU){
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
        Application* application = Application::getInstance();
        application->openURL(":setBannerAdVisible:");
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        AppUtils::setAdInvisible(false);
#endif
        this->logo->setVisible(true);
        this->menuLayer->setVisible(true);
    } else {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
        Application* application = Application::getInstance();
        application->openURL(":setBannerAdInvisible:");
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        AppUtils::setAdInvisible(true);
#endif
        this->logo->setVisible(false);
        this->menuLayer->setVisible(false);
    }
    
    if(gameModel->getGameState() == GS_PLAY){
        this->gameLayer->setVisible(true);
    } else {
        this->gameLayer->setVisible(false);
    }
}